import { createRouter, createWebHistory } from 'vue-router'
import Login from '@/views/Login.vue'
import Register from '@/views/Register.vue'

import UserLayout from '@/layouts/UserLayout.vue'
import UserApply from '@/views/user/UserApply.vue'
import UserDashboard from '@/views/user/UserDashboard.vue'
import UserBorrowed from '@/views/user/UserBorrowed.vue'
import UserReturned from '@/views/user/UserReturned.vue'
import UserPerson from '@/views/user/UserPerson.vue'

import EquipmentManagement from '@/views/admin/EquipmentManagement.vue'
import AdminLayout from '@/layouts/AdminLayout.vue'
import Dashboard from '@/views/admin/Dashboard.vue'
import ExperimentApply from '@/views/admin/ExperimentApply.vue'
import ReturnedEquipment from '@/views/admin/ReturnedEquipment.vue'
import UserProfile from '@/views/admin/UserProfile.vue'
import BorrowedEquipment from '@/views/admin/BorrowedEquipment.vue'

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    {
      path: '/',
      component: Login,
    },


    {
      path: '/admin',
      component: AdminLayout,
      redirect: '/admin/dashboard',
      children: [
        {
          path: 'dashboard',
          name: 'Dashboard',
          component: Dashboard,
          meta: { title: '首页' }
        },
        {
          path: 'equipment',
          name: 'EquipmentManagement',
          component: EquipmentManagement,
          meta: { title: '实验室材料管理' }
        },
        {
          path: 'borrowed',
          name: 'BorrowedEquipment',
          component: BorrowedEquipment,
          meta: { title: '已借器材' }
        },
        {
          path: 'apply',
          name: 'ExperimentApply',
          component: ExperimentApply,
          meta: { title: '实验申用' }
        },
        {
          path: 'returned',
          name: 'ReturnedEquipment',
          component: ReturnedEquipment,
          meta: { title: '已还器材' }
        },
        {
          path: 'profile',
          name: 'UserProfile',
          component: UserProfile,
          meta: { title: '个人信息' }
        }
      ]
    },

    {
      path: '/user',
      component: UserLayout,
      redirect: '/user/dashboard',
      children: [
        {
          path: 'dashboard',
          name: 'UserDashboard',
          component: UserDashboard,
          meta: { title: '首页' }
        },
        {
          path: 'apply',
          name: 'UserApply',
          component: UserApply,
          meta: { title: '实验申用' }
        },
        {
          path: 'borrowed',
          name: 'UserBorrowed',
          component: UserBorrowed,
          meta: { title: '已借器材' }
        },
        {
          path: 'returned',
          name: 'UserReturned',
          component: UserReturned,
          meta: { title: '已还器材' }
        },
        {
          path: 'person',
          name: 'UserPerson',
          component: UserPerson,
          meta: { title: '个人信息' }
        },

      ]
    },
    {
      path: '/register',
      component: Register,
    },
    {
      path: '/login',
      component: Login,
    },



  ],
})

// Navigation guard to handle authentication
router.beforeEach((to, from, next) => {
  // Add authentication logic here if needed
  next()
})
export default router
